import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2024-05-05
 * Time: 17:12
 */
public class Main5 {
    static class Node {
        int x;
        int y;
        int z;
        int w;

        public Node(int x, int y, int z, int w) {
            this.x = x;
            this.y = y;
            this.z = z;
            this.w = w;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int z = scanner.nextInt();
            int w = scanner.nextInt();
            nodes[i] = new Node(x, y, z, w);
        }
        // dp 初始化
        int len = 1 << n;
        double[][] dp = new double[len][n];
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < n; j++) {
                dp[i][j] = Double.MAX_VALUE;
            }
        }
        for (int i = 0; i < n; i++) {
            dp[1 << i][i] = 0;
        }
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < n; j++) {
                if (dp[i][j] == Double.MAX_VALUE) {
                    continue;
                }
                for (int k = 0; k < n; k++) {
                    if ((i & (1 << j)) == 0 || (i & (1 << k)) != 0) {
                        continue;
                    }
                    dp[i | (1 << k)][k] = Math.min(dp[i | (1 << k)][k], dp[i][j] + getDistance(nodes[j], nodes[k]));
                }
            }
        }
        double res = Double.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            res = Math.min(res, dp[len - 1][i]);
        }
        System.out.printf("%.2f", res);
    }

    public static double getDistance(Node n1, Node n2) {
        return Math.sqrt(Math.pow(n1.x - n2.x, 2) + Math.pow(n1.y - n2.y, 2)
                + Math.pow(n1.z - n2.z, 2)) * n2.w;
    }
}
